<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Web SSE</title>
    <script type="text/javascript">
        function onLoad() {
            console.log("On Load!");
            var source = new EventSource("http://localhost:8080/index.jsp");

            source.onmessage = function (event) {
                console.log(event.data);
                document.getElementById("result").innerHTML = event.data + "<br>";
            };

            source.addEventListener('myevent', function (event) {
                document.getElementById("result").innerHTML = event.data + "<br>";
            });

            source.onopen = function (event) {
                console.log("On Open!");
            };

            source.onerror = function (event) {
                console.log("On Error!");
            }
        }
    </script>
</head>
<body onload="onLoad()">
<div id="result" style="width: 500px;height: 100px;background-color: aquamarine"></div>
</body>
</html>